﻿using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;

namespace ArekChatClient
{
    static class Program
    {
        static TcpClient client;
        static void Main(string[] args)
        {
            client = new TcpClient();
            client.Connect("193.225.227.116", 54321);
            while (client.Connected)
            {
                send();   //több szállal kéne megoldani, hogy figyeljen időközönként, hogy jött-e valami üzenet, ha nem, akkor visszalszik
                recieve();
            }

        }
        static void send()
        {
            NetworkStream stream = client.GetStream();
            byte[] data;
            string msg_t;

            string msg = Console.ReadLine();
            string username = "Szandika";                    //ezt a loginablaknak kéne átadnia
            string targetname = "Broadcast";                 //ez addig maradhat, amíg nincsenek privátok
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            msg_t = username;
            for (int i = username.Length; i < 20; i++)
            {
                msg_t += " ";
            }
            msg_t += targetname;
            for (int i = (20 + targetname.Length); i < 40; i++)
            {
                msg_t += " ";
            }
            msg_t += msg;
            data = encoding.GetBytes(msg_t);
            stream.Write(data, 0, data.Length);
        }

        static byte[] buffer = new byte[256];
        static void recieve()
        {
            NetworkStream stream = client.GetStream();
            int data = stream.Read(buffer, 0, 256);
            Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, data));

        }
    }
}
